﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NanoERP.Common;
using System.Windows.Forms;
using NanoERP.Model;
using NanoERP.BaseInfo;

namespace NanoERP
{
    /// <summary>
    /// 创建窗体视图
    /// </summary>
    public class CreateFormView
    {
        /// <summary>
        /// 绑定【字典】窗体界面查询
        /// </summary>
        /// <param name="control">需要绑定控件</param>
        /// <param name="options">基础字典枚举</param>
        /// <param name="isMulti">是否多级，默认：false</param>
        /// <param name="isQuery">是否需显示查询框，默认false</param>
        /// <param name="isSelectRoot">是否选择根节点，默认：true</param>
        public static void BindDicForm(Control control, SysDicEnum options, bool isMulti = false, bool isQuery = false, bool isSelectRoot = true)
        {
            var f = new FrmDicData((int)options, isMulti, isQuery, isSelectRoot);
            if (f.ShowDialog() == DialogResult.OK)
            {
                if (f.Tag != null)
                {
                    var v = f.Tag as Sysdictable;
                    control.Text = v.Dicname;
                    control.Tag = v.Id;
                }
            }
        }

        /// <summary>
        ///  绑定【部门】窗体界面查询
        /// </summary>
        /// <param name="control">需要绑定控件</param>
        public static void BindDepartForm(Control control)
        {
            var f = new FrmDepartInfo();
            if (f.ShowDialog() == DialogResult.OK)
            {
                if (f.Tag != null)
                {
                    var v = f.Tag as Deptinfo;
                    control.Text = v.Deptname;
                    control.Tag = v.Id;
                }
            }
        }

        /// <summary>
        ///  绑定【职员】窗体界面查询
        /// </summary>
        /// <param name="control">需要绑定控件</param>
        /// <param name="isCheckBoxCell">是否显示选择列</param>
        public static void BindStaffForm(Control control, bool isCheckBoxCell = false)
        {
            var f = new FrmSelectStaff(isCheckBoxCell);
            if (f.ShowDialog() == DialogResult.OK)
            {
                if (f.Tag != null)
                {
                    var dic = f.Tag as Dictionary<long, string>;

                    control.Text = string.Join(",", dic.Values);
                    control.Tag = string.Join(",", dic.Keys);
                }
            }
        }

        /// <summary>
        ///  绑定【仓库】窗体界面查询
        /// </summary>
        /// <param name="control">需要绑定控件</param>
        public static void BindStorageForm(Control control)
        {
            var f = new FrmSelectStorage();
            if (f.ShowDialog() == DialogResult.OK)
            {
                if (f.Tag != null)
                {
                    var dic = f.Tag as Dictionary<long, string>;

                    control.Text = string.Join(",", dic.Values);
                    control.Tag = string.Join(",", dic.Keys);
                }
            }
        }

        /// <summary>
        ///  绑定【账户】窗体界面查询
        /// </summary>
        /// <param name="control">需要绑定控件</param>
        public static void BindAccountForm(Control control)
        {
            var f = new FrmSelectAccount(control.Text);
            if (f.ShowDialog() == DialogResult.OK)
            {
                if (f.Tag != null)
                {
                    var dic = f.Tag as Dictionary<long, string>;

                    control.Text = string.Join(";", dic.Values);
                    control.Tag = string.Join(";", dic.Keys);
                }
            }
        }

        /// <summary>
        ///  绑定【往来单位】窗体界面查询
        /// </summary>
        /// <param name="control">需要绑定控件</param>
        public static void BindClientForm(Control control)
        {
            var f = new FrmSelectClient();
            if (f.ShowDialog() == DialogResult.OK)
            {
                if (f.Tag != null)
                {
                    var dic = f.Tag as Dictionary<long, string>;

                    control.Text = string.Join(",", dic.Values);
                    control.Tag = string.Join(",", dic.Keys);
                }
            }
        }

        /// <summary>
        ///  绑定【物流公司】窗体界面查询
        /// </summary>
        /// <param name="control">需要绑定控件</param>
        public static void BindLogisticsForm(Control control)
        {
            var f = new FrmSelectLogistics();
            if (f.ShowDialog() == DialogResult.OK)
            {
                if (f.Tag != null)
                {
                    var dic = f.Tag as Dictionary<long, string>;

                    control.Text = string.Join(",", dic.Values);
                    control.Tag = string.Join(",", dic.Keys);
                }
            }
        }

        /// <summary>
        ///  绑定【商品】窗体界面查询
        /// </summary>
        /// <param name="control">需要绑定控件</param>
        /// <param name="isCheckBoxCell">是否显示选择列</param>
        public static void BindProductForm(Control control, bool isCheckBoxCell = false)
        {
            var f = new FrmSelectProduct(isCheckBoxCell);
            f.ShowDialog();
            control.Tag = f.Tag;
        }

        /// <summary>
        ///  绑定【采购订单】窗体界面查询
        /// </summary>
        /// <param name="control">需要绑定控件</param>
        /// <param name="isCheckBoxCell">是否显示选择列</param>
        public static void BindPurchaseOrderForm(Control control,long clientid, bool isCheckBoxCell = false)
        {
            
            var f = new FrmSelectPurchaseOrder(clientid, isCheckBoxCell);
            f.ShowDialog();
            control.Text = f.SelectedBillNo;
            control.Tag = f.Tag;
        }

        /// <summary>
        ///  绑定【采购收货】窗体界面查询
        /// </summary>
        /// <param name="control">需要绑定控件</param>
        /// <param name="isCheckBoxCell">是否显示选择列</param>
        public static void BindPurchaseBillForm(Control control, long clientid, bool isCheckBoxCell = false)
        {

            var f = new FrmSelectBill(clientid, isCheckBoxCell);
            f.ShowDialog();
            control.Text = f.SelectedBillNo;
            control.Tag = f.Tag;
        }
    }
}
